//
//  LZRushCouponDetailTitleCell.m
//  LzzizDemo
//
//  Created by xbnzd on 16/11/7.
//  Copyright © 2016年 xbnzd. All rights reserved.
//

#import "LZGrabCouponDetailTitleCell.h"
#import "GiftListLabel.h"

@interface LZGrabCouponDetailTitleCell()
@property (weak, nonatomic) IBOutlet GiftListLabel *couponTitlelabel;
@property (weak, nonatomic) IBOutlet UILabel *couponCountLabel;
@property (weak, nonatomic) IBOutlet UIImageView *couponIcon;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *couponTitleBottomToCouponCountConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *couponTitleBottomSupeviewConstraint;


@end

@implementation LZGrabCouponDetailTitleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self configureLabel];
    self.couponTitlelabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
    self.couponCountLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - self.couponIcon.intrinsicContentSize.width - 25;
    // Initialization code
}

- (void)loadTitle:(NSString *)title CouponCount:(NSInteger)couponCount CouponState:(CouponState)couponState
{
    [self setRulesContentLabelText:title];
    self.couponCountLabel.text = [NSString stringWithFormat:@"%ld %@",(long)couponCount,LZLocalizedString(@"group_left", nil)];
    
    if (couponState == kCoupon_used|| couponState == kCoupon_notUsed || couponState == kCoupon_expired) {
        _couponTitleBottomSupeviewConstraint.priority = 999;
        _couponTitleBottomToCouponCountConstraint.priority = 250;
        _couponCountLabel.hidden = YES;
        _couponIcon.hidden = YES;

    }else{
        _couponTitleBottomSupeviewConstraint.priority = 250;
        _couponTitleBottomToCouponCountConstraint.priority = 999;
        _couponCountLabel.hidden = NO;
        _couponIcon.hidden = NO;
    }
    
}

- (void)setRulesContentLabelText:(NSString *)text
{
    if (text.length <= 0) {
        return;
    }
    extern CGFloat textLineSpace;
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    
    [style setLineSpacing:textLineSpace];
    [style setLineBreakMode:NSLineBreakByWordWrapping];
    [style setAlignment:NSTextAlignmentLeft];
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attStr.length)];
    self.couponTitlelabel.attributedText = attStr;
}

#pragma mark -
#pragma mark action
- (void)configureLabel
{
    [self.couponTitlelabel setVerticalAlignment:VerticalAlignmentTop];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
